﻿package mortal.game.view.systemHistory
{
    import com.mui.controls.*;
    import flash.events.*;
    import mortal.component.window.*;
    import mortal.game.cache.*;
    import mortal.game.view.common.*;
    import mortal.game.view.wizard.*;
    import mortal.mvc.interfaces.*;

    public class SysHistroyWindow extends SmallWindow
    {
        private var _tabBar:GTabarNew;
        private var _textArea:GTextArea;
        private static var _instance:SysHistroyWindow;

        public function SysHistroyWindow(param1:ILayer = null)
        {
            super(param1);
            setSize(300, 285);
            title = "历史记录";
            return;
        }// end function

        override protected function addWindowLine() : void
        {
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            titleHeight = 60;
            super.createDisposedChildrenImpl();
            this._tabBar = UIFactory.gTabBarNew(2, 32, [{label:"系统信息", name:"systemMsg"}, {label:"战斗信息", name:"fightMsg"}], 304, 285, 63, 22, this, this.onTabBarChange);
            this._textArea = UIFactory.textArea("", 18, 68, 280, 216, this);
            this.updateMsg();
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            this._tabBar.dispose();
            this._tabBar = null;
            this._textArea.dispose();
            this._textArea = null;
            super.disposeImpl();
            return;
        }// end function

        private function onTabBarChange(event:Event) : void
        {
            this.updateMsg();
            return;
        }// end function

        private function updateMsg() : void
        {
            var _loc_1:Array = null;
            var _loc_2:int = 0;
            if (this._tabBar.selectedIndex == 0)
            {
                _loc_1 = Cache.instance.sysHis.history;
            }
            else
            {
                _loc_1 = Cache.instance.sysHis.fightHis;
            }
            var _loc_3:* = _loc_1.length;
            var _loc_4:String = "";
            while (_loc_2 < _loc_3)
            {
                
                _loc_4 = _loc_4 + _loc_1[_loc_2];
                _loc_2++;
            }
            this._textArea.htmlText = _loc_4;
            this._textArea.verticalScrollPosition = this._textArea.maxVerticalScrollPosition;
            return;
        }// end function

        public function addHistory(param1:String, param2:int = 0) : void
        {
            var _loc_3:* = this._textArea.verticalScrollPosition == this._textArea.maxVerticalScrollPosition;
            if (param2 == this._tabBar.selectedIndex)
            {
                this._textArea.htmlText = this._textArea.htmlText + param1;
            }
            if (_loc_3)
            {
                this._textArea.verticalScrollPosition = this._textArea.maxVerticalScrollPosition;
            }
            return;
        }// end function

        public static function get instance() : SysHistroyWindow
        {
            if (!_instance)
            {
                _instance = new SysHistroyWindow;
            }
            return _instance;
        }// end function

        public static function hasInstance() : Boolean
        {
            return _instance != null;
        }// end function

    }
}
